<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script type="text/javascript">
    const _instanceof = (target, Fn) => {
      // 补全代码---以布尔值的形式返回第一个参数是否在第二个参数的原型链上
      //在原型链上一直寻找，直到为null为止
      let flag = false
      while (target.__proto__) {
        if (target.__proto__ === Fn.prototype) {
          flag = true
          break
        } else {
          target = target.__proto__    //target.__proto__===构造函数.prototype ,因此下次的target.__proto__便是.prototype.__proto__顺着原型链
        }
      }
      return flag
    }

    const arr = []
    console.log(_instanceof(arr, Array))


    // const arr = []
    // console.log(arr.__proto__ == Array.prototype)
    // console.log(Array.prototype.__proto__ === Object.prototype)
    // console.log(arr instanceof Object)

    // function fn() { }
    // console.log('--------------------------')

    // console.log(fn.__proto__ === Function.prototype)
    // console.log(Function.prototype.__proto__ === Object.prototype)

    // console.log(typeof fn)   //function
    // console.log(typeof /(\d)/)   //object

  </script>
</body>

</html>